package net.yeah.mickey_zhouyou.framework.frame;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Toolkit;

import javax.swing.Icon;
import javax.swing.JFrame;
import javax.swing.JTabbedPane;

import net.yeah.mickey_zhouyou.framework.util.Constants;
import net.yeah.mickey_zhouyou.framework.util.ImageUtil;

public class MainFrame extends JFrame {

	private static final long serialVersionUID = -7289868303627125954L;

	private static MainFrame frame;

	private JTabbedPane tabbedPane;

	private MainFrame() {
		super.setTitle("My Knowledge Base");
		super.setIconImage(ImageUtil.loadByPath(Constants.ICON_PATH_MAINFRAME));

		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

		final int width = screenSize.width * 4 / 5;
		final int height = screenSize.height * 4 / 5;
		
		final int x = (screenSize.width - width) / 2;
		final int y = (screenSize.height - height) / 2;

		super.setSize(width, height);
		super.setLocation(x, y);

		tabbedPane = new JTabbedPane();
		super.add(tabbedPane, BorderLayout.CENTER);
	}

	MainFrame addTab(String title, Icon icon, Component component) {
		addTab(title, icon, component, null);
		return this;
	}

	MainFrame addTab(String title, Icon icon, Component component, String tip) {
		tabbedPane.addTab(title, icon, component, tip);
		return this;
	}

	public static MainFrame getMainFrame() {
		if (frame == null) {
			synchronized (MainFrame.class) {
				if (frame == null)
					frame = new MainFrame();
			}
		}
		return frame;
	}

}
